package com.ruoyi.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.Newsbulletin;
import com.ruoyi.system.service.INewsbulletinService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 新闻与公告Controller
 * 
 * @author dahaoren
 * @date 2024-07-08
 */
@RestController
@RequestMapping("/system/newsbulletin")
public class NewsbulletinController extends BaseController
{
    @Autowired
    private INewsbulletinService newsbulletinService;

    /**
     * 查询新闻与公告列表
     */
    @PreAuthorize("@ss.hasPermi('system:newsbulletin:list')")
    @GetMapping("/list")
    public TableDataInfo list(Newsbulletin newsbulletin)
    {
        startPage();
        List<Newsbulletin> list = newsbulletinService.selectNewsbulletinList(newsbulletin);
        return getDataTable(list);
    }

    /**
     * 导出新闻与公告列表
     */
    @PreAuthorize("@ss.hasPermi('system:newsbulletin:export')")
    @Log(title = "新闻与公告", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Newsbulletin newsbulletin)
    {
        List<Newsbulletin> list = newsbulletinService.selectNewsbulletinList(newsbulletin);
        ExcelUtil<Newsbulletin> util = new ExcelUtil<Newsbulletin>(Newsbulletin.class);
        util.exportExcel(response, list, "新闻与公告数据");
    }

    /**
     * 获取新闻与公告详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:newsbulletin:query')")
    @GetMapping(value = "/{nbId}")
    public AjaxResult getInfo(@PathVariable("nbId") String nbId)
    {
        return success(newsbulletinService.selectNewsbulletinByNbId(nbId));
    }

    /**
     * 新增新闻与公告
     */
    @PreAuthorize("@ss.hasPermi('system:newsbulletin:add')")
    @Log(title = "新闻与公告", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Newsbulletin newsbulletin)
    {
        return toAjax(newsbulletinService.insertNewsbulletin(newsbulletin));
    }

    /**
     * 修改新闻与公告
     */
    @PreAuthorize("@ss.hasPermi('system:newsbulletin:edit')")
    @Log(title = "新闻与公告", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Newsbulletin newsbulletin)
    {
        return toAjax(newsbulletinService.updateNewsbulletin(newsbulletin));
    }

    /**
     * 删除新闻与公告
     */
    @PreAuthorize("@ss.hasPermi('system:newsbulletin:remove')")
    @Log(title = "新闻与公告", businessType = BusinessType.DELETE)
	@DeleteMapping("/{nbIds}")
    public AjaxResult remove(@PathVariable String[] nbIds)
    {
        return toAjax(newsbulletinService.deleteNewsbulletinByNbIds(nbIds));
    }
}
